package org.cxfexample.callback;

import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.security.WSPasswordCallback;

public class SecurityCallBackExample implements CallbackHandler {

	private Log logger = LogFactory.getLog(this.getClass());
	
	public void handle(Callback[] callbacks) throws IOException,
			UnsupportedCallbackException {
		  WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
		  
		logger.info("call back called");
        if (pc.getIdentifier().equals("joe")) {
           if (!pc.getPassword().equals("password")) {
                throw new IOException("wrong password");
           }
        }

	}

}
